<template>
  <view class="container">
	<xk-header :headerbg="true" class="header" :back="true" title="大楼门禁"></xk-header>
	<view class="box1">
		<view class="tips1">请将二维码对准识别设备扫码出入</view>
		<view><image class="menjinma" mode="widthFix" :src="(imgUrl+'/wx/qrcode.png')" ></image></view>
		<view class="timetext">门禁码有效期至{{timeText|date('yyyy-mm-dd hh:MM:ss')}}   限1次</view>
		<view><button type="primary" size="mini" class="refresh" @click="refresh"><u-icon name="reload" size="24" color="#FFF"></u-icon> 刷新门禁码</button></view>
		<view class="tips2"><u-icon name="error-circle" customStyle="margin-right:2px;"></u-icon> 请勿频繁刷新门禁码，此码为动态码，请勿截屏使用</view>
	</view>
	<u-toast ref="uToast" />
  </view>
</template>

<script>
  /* import { setCartTabBadge } from '@/core/app'
  import * as Api from '@/api/page'
  import Page from '@/components/page' */

  const App = getApp()

  export default {
    components: {},
    data() {
      return {
		  imgUrl:this.$config.BASE_imgUrl,
        // 页面参数
        options: {},
        // 页面属性
        page: {},
        // 页面元素
        items: [],
		timeText:Date.parse(new Date())+120*1000,
      }
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
      // 当前页面参数
      this.options = options
      // 加载页面数据
      //this.getPageData();
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
      // 更新购物车角标
      //setCartTabBadge()
    },

    methods: {
      refresh(){
		 var that=this;
		 this.$refs.uToast.show({
			type: 'loading',
			title: '刷新装载',
			message: "刷新装载",
			duration:1000,
			complete(){
				that.timeText=Date.parse(new Date())+120*1000;
			}
		 });
	  },
      /**
       * 加载页面数据
       * @param {Object} callback
       */
      getPageData(callback) {
        const app = this
        const pageId = app.options.pageId || 0
        Api.detail(pageId)
          .then(result => {
            // 设置页面数据
            const { data: { pageData } } = result
            app.page = pageData.page
            app.items = pageData.items
            // 设置顶部导航栏栏
            app.setPageBar();
          })
          .finally(() => callback && callback())
      },

      /**
       * 设置顶部导航栏
       */
      setPageBar() {
        const {
          page
        } = this
        // 设置页面标题
        uni.setNavigationBarTitle({
          title: page.params.title
        });
        // 设置navbar标题、颜色
        uni.setNavigationBarColor({
          frontColor: page.style.titleTextColor === 'white' ? '#ffffff' : '#000000',
          backgroundColor: page.style.titleBackgroundColor
        })
      },

    },

    /**
     * 下拉刷新
     */
    onPullDownRefresh() {
      // 获取首页数据
      this.getPageData(() => {
        uni.stopPullDownRefresh()
      })
    },

    /**
     * 分享当前页面
     */
    onShareAppMessage() {
      const app = this
      const { page } = app
      return {
        title: page.params.share_title,
        path: "/pages/index/index?" + app.$getShareUrlParams()
      }
    },

    /**
     * 分享到朋友圈
     * 本接口为 Beta 版本，暂只在 Android 平台支持，详见分享到朋友圈 (Beta)
     * https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share-timeline.html
     */
    onShareTimeline() {
      const app = this
      const { page } = app
      return {
        title: page.params.share_title,
        path: "/pages/index/index?" + app.$getShareUrlParams()
      }
    }

  }
</script>

<style lang="scss" scoped>
   page{
		background:#F5F5F5!important;
	}
  .container {
    background: #F5F5F5;
  }
  .box1{
	 background:#FFFFFF;
	 text-align:center;
	 margin:20rpx;
	 padding:80rpx 50rpx 80rpx 50rpx;
	 font-size:24rpx;
	 border-radius:12rpx;
  }
  .menjinma{
	  width:90%;
  }
  .refresh{
	  display:inline-flex;
	  text-align: center;
	  width:400rpx;
	  border-radius:50rpx;
	  padding:20rpx 0px 20rpx 80rpx;
	  margin:50rpx auto 50rpx auto;
	  background:#007aff;
  }
  .tips2{
	  display:inline-flex;
	  color:#999;
  }
</style>
